/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package koor.action.student;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import koor.action.Action;
import koor.action.ActionResult;
import koor.entity.Student;
import koor.persistent.StudentDAO;
import koor.service.ServiceLocator;

/**
 * The
 * <code>StudentListAction</code> class represents action, used to view student
 * list
 *
 * @author Admin
 */
public class StudentListAction implements Action {

    @Override
    public String getName() {
        return "student.list";
    }

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        List<Student> studentList;
        if (request.getSession().getAttribute("search") == null) {
            studentList = ServiceLocator.getService(StudentDAO.class).findAll();
        } else {
            studentList = ServiceLocator.getService(StudentDAO.class).findByName((String) request.getSession().getAttribute("search"));      
        }
        request.setAttribute("studentList", studentList);
        return ActionResult.forward("StudentView/StudentListView.jsp");
    }
}
